package me.sdevil507.biz.common.area.controller;

import lombok.extern.slf4j.Slf4j;
import me.sdevil507.biz.common.area.dto.CommonAreaParamsDto;
import me.sdevil507.biz.common.area.dto.CommonAreaResultDto;
import me.sdevil507.biz.common.area.mapper.CommonAreaMapper;
import me.sdevil507.biz.common.area.service.CommonAreaService;
import me.sdevil507.supports.result.ApiResultDTO;
import me.sdevil507.supports.result.ApiResultGenerator;
import me.sdevil507.supports.status.ApiStatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 地区码表[CommonAreaController]
 *
 * @author sdevil507
 * created on 2020-07-02 14:15:11
 */
@Controller
@RequestMapping("/api/common/area")
@Slf4j
public class CommonAreaController {

    @Autowired
    private CommonAreaService commonAreaService;

    @Autowired
    private CommonAreaMapper commonAreaMapper;

    /**
     * 获取全部信息列表
     *
     * @param dto 聚合查询/分页/排序参数
     * @return 信息列表
     */
    @RequestMapping(value = "/readAll", method = RequestMethod.POST)
    @ResponseBody
    public ApiResultDTO readAll(@RequestBody CommonAreaParamsDto dto) {
        List<CommonAreaResultDto> list = commonAreaMapper.pos2dtos(commonAreaService.readAll(dto));
        return ApiResultGenerator.create(ApiStatusCode.SUCCESS.getCode(), ApiStatusCode.SUCCESS.getDescription(), list);
    }

}